package com.skhu.as.dao;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;

import com.skhu.as.domain.Worker;
import com.skhu.as.mapper.WorkerM;

public class WorkerD {

	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	public List<Worker> getWorkerList(){
		String sql = "SELECT worker_no, name, major, contact_number, use FROM worker WHERE use = 'use'";
		List<Worker> workerList = jdbcTemplate.query(sql, new WorkerM());
		return workerList;
	}
	
	public int getWorkerMaxNo(){
		String sql = "SELECT MAX(worker_no) FROM worker WHERE use = 'use'";
		int result = jdbcTemplate.queryForInt(sql);
		return result;
	}
	
	public int deleteWorker(int workerNo){
		String sql = "UPDATE worker SET use = 'no' WHERE worker_no = ?";
		Object[] param = new Object[]{
				workerNo
		};
		return jdbcTemplate.update(sql, param);
	}
	
	public int insertWorker(Worker worker){
		String sql = "INSERT INTO worker VALUES (?,?,?,?,?)";
		Object[] param = new Object[]{
				worker.getWorkerNo(),
				worker.getName(),
				worker.getMajor(),
				worker.getContactNumber(),
				"use"
		};
		return jdbcTemplate.update(sql, param);
	}
	
}
